package TeacherEvaluation.com.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import TeacherEvaluation.com.entity.Admin;
import TeacherEvaluation.com.entity.ResultMsg;
import TeacherEvaluation.com.entity.Student;
import TeacherEvaluation.com.entity.Teacher;
/**
 * 主页所用控制器
 * @author azhao
 *2019/09/16
 */
@Controller
public class indexController {
	//管理员访问index
		@RequestMapping("/adminIndex")
		public ModelAndView Index(HttpServletRequest request) {
			ModelAndView mv = new ModelAndView("admin/index");
			ModelAndView mv2 = new ModelAndView("redirect:/login");
			HttpSession session=request.getSession();
			Admin admin=(Admin) session.getAttribute("user");
			if(session.getAttribute("user")!=null) {
				mv.addObject("user",admin);
				return mv;
			}else {
				return mv2;
			}
		}
		
		//老师访问index1
		@RequestMapping("/teacherIndex")
		public ModelAndView teacherIndex(HttpServletRequest request) {
			ModelAndView mv = new ModelAndView("teachers/index");
			ModelAndView mv2 = new ModelAndView("redirect:/login");
			HttpSession session=request.getSession();
			Teacher teacher=(Teacher) session.getAttribute("user");
			if(session.getAttribute("user")!=null) {
				mv.addObject("user",teacher);
				return mv;
			}else {
				return mv2;
			}
		}
		//学生访问index2
		@RequestMapping("/studentIndex")
		public ModelAndView studentIndex(HttpServletRequest request) {
			ModelAndView mv = new ModelAndView("students/index");
			ModelAndView mv2 = new ModelAndView("redirect:/login");
			HttpSession session=request.getSession();
			Student student=(Student) session.getAttribute("user");
			if(session.getAttribute("user")!=null) {
				mv.addObject("user",student);
				return mv;
			}else {
				return mv2;
			}
		}
		@RequestMapping("/exit_submit")
		public ResultMsg exit_submit(HttpServletRequest request,String name) {
			if(name.equals("11")) {
				HttpSession session=request.getSession();
				session.invalidate();
				return new ResultMsg(1, "退出!");
			}
			return new ResultMsg(0, "退出失败!");
			
		}
}
